﻿using PLCTest.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;

namespace PLCTest.BO
{
    public class MatterPlanarFoldMachine2WriteWcsAction
    {
        public MatterPlanarFoldMachine2WriteWcsAction() { }
        public MatterPlanarFoldMachine2WriteWcsAction(
            int equipmentCode
            , int taskCode
            , int toEquipmentCode
            , string palletBarcode
            , short palletWeight
            , string palletBarcode1
            , string palletBarcode2
            , string palletBarcode3
            , string palletBarcode4
            , string palletBarcode5
            , string palletBarcode6
            , string palletBarcode7
            , string palletBarcode8
            , short palletWeight1
            , short palletWeight2
            , short palletWeight3
            , short palletWeight4
            , short palletWeight5
            , short palletWeight6
            , short palletWeight7
            , short palletWeight8
            , short actionType
            , byte palletType
            , byte alrmCode
            , byte signalTask = 0
            , byte reserve2 = 0
            , byte reserve3 = 0
            , byte reserve4 = 0
            , string agvTask = "")
        {

            EquipmentCode = equipmentCode.ToString();   //设备号
            TaskCode = taskCode;  //任务号
            ToEquipmentCode = toEquipmentCode;  //目标设备号
            PalletBarcode = palletBarcode;  //托盘码
            PalletWeight = palletWeight;  //托盘重量
            PalletBarcode1 = palletBarcode1;
            PalletBarcode2 = palletBarcode2;
            PalletBarcode3 = palletBarcode3;
            PalletBarcode4 = palletBarcode4;
            PalletBarcode5 = palletBarcode5;
            PalletBarcode6 = palletBarcode6;
            PalletBarcode7 = palletBarcode7;
            PalletBarcode8 = palletBarcode8;
            PalletWeight1 = palletWeight1;
            PalletWeight2 = palletWeight2;
            PalletWeight3 = palletWeight3;
            PalletWeight4 = palletWeight4;
            PalletWeight5 = palletWeight5;
            PalletWeight6 = palletWeight6;
            PalletWeight7 = palletWeight7;
            PalletWeight8 = palletWeight8;
            ActionType = actionType;  //握手类型
            PalletType = palletType;  //托盘类型
            AlrmCode = alrmCode;  //报警代码
            SignalTask = signalTask;  //是否单机任务
            Reserve2 = reserve2;  //预留2
            Reserve3 = reserve3;  //预留3
            Reserve4 = reserve4;  //预留4
            AgvTaskCode = agvTask; //AGV任务号
        }

        /// <summary>
        /// 当前设备号
        /// </summary>
        public string EquipmentCode { get; set; }

        /// <summary>
        /// 任务号
        /// </summary>
        public int TaskCode { get; set; }
        /// <summary>
        /// 目标设备号
        /// </summary>
        public int ToEquipmentCode { get; set; }

        /// <summary>
        /// 母托盘条码
        /// </summary>
        public string PalletBarcode { get; set; }
        /// <summary>
        /// 母托盘重量
        /// </summary>
        public short PalletWeight { get; set; }
        /// <summary>
        /// 子托盘码1
        /// </summary>
        public string PalletBarcode1 { get; set; }
        /// <summary>
        /// 子托盘码2
        /// </summary>
        public string PalletBarcode2 { get; set; }
        /// <summary>
        /// 子托盘码3
        /// </summary>
        public string PalletBarcode3 { get; set; }
        /// <summary>
        /// 子托盘码4
        /// </summary>
        public string PalletBarcode4 { get; set; }
        /// <summary>
        /// 子托盘码5
        /// </summary>
        public string PalletBarcode5 { get; set; }
        /// <summary>
        /// 子托盘码6
        /// </summary>
        public string PalletBarcode6 { get; set; }
        /// <summary>
        /// 子托盘码7
        /// </summary>
        public string PalletBarcode7 { get; set; }
        /// <summary>
        /// 子托盘码8
        /// </summary>
        public string PalletBarcode8 { get; set; }
        /// <summary>
        /// 子托盘1重量
        /// </summary>
        public short PalletWeight1 { get; set; }
        /// <summary>
        /// 子托盘2重量
        /// </summary>
        public short PalletWeight2 { get; set; }
        /// <summary>
        /// 子托盘3重量
        /// </summary>
        public short PalletWeight3 { get; set; }
        /// <summary>
        /// 子托盘4重量
        /// </summary>
        public short PalletWeight4 { get; set; }
        /// <summary>
        /// 子托盘5重量
        /// </summary>
        public short PalletWeight5 { get; set; }
        /// <summary>
        /// 子托盘6重量
        /// </summary>
        public short PalletWeight6 { get; set; }
        /// <summary>
        /// 子托盘7重量
        /// </summary>
        public short PalletWeight7 { get; set; }
        /// <summary>
        /// 子托盘8重量
        /// </summary>
        public short PalletWeight8 { get; set; }
        /// <summary>
        /// 动作类型
        /// </summary>
        public short ActionType { get; set; }
        /// <summary>
        /// 托盘类型
        /// </summary>
        public byte PalletType { get; set; }
        /// <summary>
        /// 故障代码
        /// </summary>
        public byte AlrmCode { get; set; }
        /// <summary>
        /// 是否单机任务
        /// </summary>
        public byte SignalTask { get; set; }
        /// <summary>
        /// 预留2
        /// </summary>
        public byte Reserve2 { get; set; }
        /// <summary>
        /// 预留3
        /// </summary>
        public byte Reserve3 { get; set; }
        /// <summary>
        /// 预留4
        /// </summary>
        public byte Reserve4 { get; set; }


        /// <summary>
        /// agv任务号
        /// </summary>
        public string AgvTaskCode { get; set; }


        public byte[] Deserialize()
        {
            byte[] bytes = new byte[240];

            HelperByte.SetDIntAt(bytes, 0, EquipmentCode.ToInt32());
            HelperByte.SetDIntAt(bytes, 4, TaskCode);
            HelperByte.SetDIntAt(bytes, 8, ToEquipmentCode);
            HelperByte.SetByteAt(bytes, 12, 18);
            byte length = Convert.ToByte(PalletBarcode.Length);
            HelperByte.SetByteAt(bytes, 13, length);
            HelperByte.SetCharsAt(bytes, 14, PalletBarcode);
            HelperByte.SetIntAt(bytes, 32, PalletWeight);
            //子托盘码
            HelperByte.SetByteAt(bytes, 34, 18);
            byte lengthPalletBarcode1 = Convert.ToByte(PalletBarcode1.Length);
            HelperByte.SetByteAt(bytes, 35, lengthPalletBarcode1);
            HelperByte.SetCharsAt(bytes, 36, PalletBarcode1);

            HelperByte.SetByteAt(bytes, 54, 18);
            byte lengthPalletBarcode2 = Convert.ToByte(PalletBarcode2.Length);
            HelperByte.SetByteAt(bytes, 55, lengthPalletBarcode2);
            HelperByte.SetCharsAt(bytes, 56, PalletBarcode2);

            HelperByte.SetByteAt(bytes, 74, 18);
            byte lengthPalletBarcode3 = Convert.ToByte(PalletBarcode3.Length);
            HelperByte.SetByteAt(bytes, 75, lengthPalletBarcode3);
            HelperByte.SetCharsAt(bytes, 76, PalletBarcode3);

            HelperByte.SetByteAt(bytes, 94, 18);
            byte lengthPalletBarcode4 = Convert.ToByte(PalletBarcode4.Length);
            HelperByte.SetByteAt(bytes, 95, lengthPalletBarcode4);
            HelperByte.SetCharsAt(bytes, 96, PalletBarcode4);

            HelperByte.SetByteAt(bytes, 114, 18);
            byte lengthPalletBarcode5 = Convert.ToByte(PalletBarcode5.Length);
            HelperByte.SetByteAt(bytes, 115, lengthPalletBarcode5);
            HelperByte.SetCharsAt(bytes, 116, PalletBarcode5);

            HelperByte.SetByteAt(bytes, 134, 18);
            byte lengthPalletBarcode6 = Convert.ToByte(PalletBarcode6.Length);
            HelperByte.SetByteAt(bytes, 135, lengthPalletBarcode6);
            HelperByte.SetCharsAt(bytes, 136, PalletBarcode6);

            HelperByte.SetByteAt(bytes, 154, 18);
            byte lengthPalletBarcode7 = Convert.ToByte(PalletBarcode7.Length);
            HelperByte.SetByteAt(bytes, 155, lengthPalletBarcode7);
            HelperByte.SetCharsAt(bytes, 156, PalletBarcode7);

            HelperByte.SetByteAt(bytes, 174, 18);
            byte lengthPalletBarcode8 = Convert.ToByte(PalletBarcode8.Length);
            HelperByte.SetByteAt(bytes, 175, lengthPalletBarcode8);
            HelperByte.SetCharsAt(bytes, 176, PalletBarcode8);
            //子托盘重量
            HelperByte.SetIntAt(bytes, 194, PalletWeight1);
            HelperByte.SetIntAt(bytes, 196, PalletWeight2);
            HelperByte.SetIntAt(bytes, 198, PalletWeight3);
            HelperByte.SetIntAt(bytes, 200, PalletWeight4);
            HelperByte.SetIntAt(bytes, 202, PalletWeight5);
            HelperByte.SetIntAt(bytes, 204, PalletWeight6);
            HelperByte.SetIntAt(bytes, 206, PalletWeight7);
            HelperByte.SetIntAt(bytes, 208, PalletWeight8);

            HelperByte.SetIntAt(bytes, 210, ActionType);
            HelperByte.SetByteAt(bytes, 212, PalletType);
            HelperByte.SetByteAt(bytes, 213, AlrmCode);
            HelperByte.SetByteAt(bytes, 214, SignalTask);
            HelperByte.SetByteAt(bytes, 215, Reserve2);
            HelperByte.SetByteAt(bytes, 216, Reserve3);
            HelperByte.SetByteAt(bytes, 217, Reserve4);

            HelperByte.SetByteAt(bytes, 218, 20);
            byte lengthAgvTaskCode = Convert.ToByte(AgvTaskCode.Length);
            HelperByte.SetByteAt(bytes, 219, lengthPalletBarcode8);
            HelperByte.SetCharsAt(bytes, 220, PalletBarcode8);

            return bytes;
        }

    }
}
